<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "quiz.Account" %>
<%@ page import = "quiz.Result" %>
<%@ page import = "java.util.ArrayList" %>
<%
	ArrayList<Result> activity = (ArrayList<Result>)request.getAttribute("recentResults");
	Account a = (Account)request.getAttribute("profileAccount");
	Account me = (Account)request.getSession().getAttribute("account");
	
	boolean hideFriendButton = false;
	if (me == null || a.getFriends().contains(me)) hideFriendButton = true;
	
	boolean areFriends = false;
	if (me != null && a.getFriends().contains(me)) areFriends = true;
	
	String possesiveName = a.getName();
	if (possesiveName.charAt(possesiveName.length() - 1) == 's')
		possesiveName += "'";
	else
		possesiveName += "'s";
	possesiveName += " profile";
	
	String title = possesiveName + " | Quizzard";
%>
<jsp:include page="templates/header.jsp" flush="true">
	<jsp:param value = "<%= title %>" name = "title" />
</jsp:include>
<jsp:include page="templates/title_bar.jsp" flush = "true">
	<jsp:param value = "<%= possesiveName %>" name = "title" />
</jsp:include>
<div id = "content">
<div class = "center">

<div id = "activity" class = "profile"><div class = "section_title">Recent Activity 
<%
	if (!hideFriendButton) out.println("<a href = \"SendMessage?friendID="+a.getID()+"\"><span class = \"btn\">+ Add Friend</span></a>");
	if (areFriends) out.println("<a href = \"RemoveFriend?friendID="+a.getID()+"\"><span class = \"btn\">Unfriend</span></a>");

	if (me != null && me.isAdmin()) {
		if (!a.isAdmin()) out.println("<a href = \"MakeAdmin?id="+a.getID()+"\"><span class = \"btn\">Make Admin</span></a>");
		out.println("<a href = \"RemoveAccount?id="+a.getID()+"\"><span class = \"btn\">Delete Account</span></a>");
	}
%>
</div>
<%
	if (activity == null || activity.size() == 0) out.println(a.getName()+" hasn't taken any quizzes!");
	for (Result r: activity) {
		out.println("<div id = \"result\"><a href = \"Profile?id="+r.getUser().getID()+"\">"+r.getUser().getName()+"</a> scored "+r.getScore()+" on <a href = \"ShowSelectedQuiz?id="+r.getQuiz().getID()+"\">"+r.getQuiz().getName()+"</a></div>");
	}
%>
</div>
</div>
</div>
<jsp:include page="templates/footer.jsp" flush="true" />